package com.spider.hhtplat;


import io.webfolder.cdp.Launcher;
import io.webfolder.cdp.session.Session;
import io.webfolder.cdp.session.SessionFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;

import java.io.IOException;
import java.util.ArrayList;

/**
 * @author hht
 * @ClassName Test
 * @Description TODO
 * @Date 2019/9/11 16:28
 * @VERSION 1.0
 */
public class Test {
        public static void main(String args[]) throws Exception {
            ArrayList<String> arguments= new ArrayList<String>();
            //如果添加此行就不会弹出google浏览器
            //arguments.add("--headless");
            Launcher launcher = new Launcher();
            //第一个参数是本地谷歌浏览器的可执行地址
            //"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
            try (SessionFactory factory = launcher.launch("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",arguments);
                 Session session = factory.create()) {
                //这个参数是你想要爬取的网址
                session.navigate("https://blog.csdn.net/weixin_43085439/article/details/83994673");
                //等待加载完毕
                session.waitDocumentReady();
                //获得爬取的数据
                String content = (String) session.getContent();
                //使用Jsoup转换成可以解析的Document
                org.jsoup.nodes.Document document = Jsoup.parse(content);
                System.out.println(document.body());
            }
        }
}
